using System;
using System.Collections.Generic;
using System.Web;
using System.Web.SessionState;
using System.Linq;
using System.Web.Mvc;
using TimeTableManagement.Entities;
using System.Web.Security;
using System.Data;
using TimeTableManagement.Models;
using System.ComponentModel.DataAnnotations;

namespace TimeTableManagement.Entities
{
    /// <summary>
    /// 
    /// </summary>
    public class Tb_Log
    {
        public int id { get; set; }
        public Nullable<System.DateTime> date { get; set; }
        [Display(Name = "Type")]
        public string type { get; set; }
        public string action { get; set; }
        public string user { get; set; }
        public string result { get; set; }
        public string session { get; set; }
        public string option { get; set; }

    }
    public class LOG
    {
        public static void write(String type, String user, String action, String result, String option)
        {
            QLSVContext _context = new QLSVContext();
            Tb_Log log = new Tb_Log();
            log.date = DateTime.Now;
            log.type = type;
            log.action = action;
            log.user = user;
            log.result = result;
            log.session = Functions.RandomPassword(32);
            log.option = option;
            _context.Tb_Log.Add(log);
            _context.SaveChanges();
            _context.Dispose();
        }
        public static void system_infor(String user, String action, String result)
        {
            LOG.write("infor", user, action, result, "system");
        }
        public static void system_error(String user, String action, String result)
        {
            LOG.write("error", user, action, result, "system");
        }
        public static void system_warning(String user, String action, String result)
        {
            LOG.write("warning", user, action, result, "system");
        }
        public static void user_infor(String user, String action, String result)
        {
            LOG.write("infor", user, action, result, "user");
        }
        public static void user_error(String user, String action, String result)
        {
            LOG.write("error", user, action, result, "user");
        }
        public static void user_warning(String user, String action, String result)
        {
            LOG.write("warning", user, action, result, "user");
        }
        public static void database_infor(String user, String action, String result)
        {
            LOG.write("infor", user, action, result, "database");
        }
        public static void database_error(String user, String action, String result)
        {
            LOG.write("error", user, action, result, "database");
        }
        public static void database_warning(String user, String action, String result)
        {
            LOG.write("warning", user, action, result, "database");
        }
    }
}

